namespace XRM.Security.DataAccess.Context
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class RenameUserIdentityCenter : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.UserIdentityCenter", "IdentityCenterId", "dbo.IdentityCenter");
            DropForeignKey("dbo.UserIdentityCenter", "UserRegisterId", "dbo.UserRegister");
            DropIndex("dbo.UserIdentityCenter", new[] { "UserRegisterId" });
            DropIndex("dbo.UserIdentityCenter", new[] { "IdentityCenterId" });
            CreateTable(
                "dbo.UserInfoSystem",
                c => new
                    {
                        UserRegisterId = c.Int(nullable: false),
                        InfoSystemId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.UserRegisterId, t.InfoSystemId })
                .ForeignKey("dbo.InfoSystem", t => t.InfoSystemId, cascadeDelete: true)
                .ForeignKey("dbo.UserRegister", t => t.UserRegisterId, cascadeDelete: true)
                .Index(t => t.UserRegisterId)
                .Index(t => t.InfoSystemId);
            
            DropTable("dbo.UserIdentityCenter");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.UserIdentityCenter",
                c => new
                    {
                        UserRegisterId = c.Int(nullable: false),
                        IdentityCenterId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.UserRegisterId, t.IdentityCenterId });
            
            DropForeignKey("dbo.UserInfoSystem", "UserRegisterId", "dbo.UserRegister");
            DropForeignKey("dbo.UserInfoSystem", "InfoSystemId", "dbo.InfoSystem");
            DropIndex("dbo.UserInfoSystem", new[] { "InfoSystemId" });
            DropIndex("dbo.UserInfoSystem", new[] { "UserRegisterId" });
            DropTable("dbo.UserInfoSystem");
            CreateIndex("dbo.UserIdentityCenter", "IdentityCenterId");
            CreateIndex("dbo.UserIdentityCenter", "UserRegisterId");
            AddForeignKey("dbo.UserIdentityCenter", "UserRegisterId", "dbo.UserRegister", "UserRegisterId", cascadeDelete: true);
            AddForeignKey("dbo.UserIdentityCenter", "IdentityCenterId", "dbo.IdentityCenter", "IdentityCenterId", cascadeDelete: true);
        }
    }
}
